package com.qdy.api;

import com.jiai.core.tools.RestResultGenerator;
import com.jiai.exception.ServiceException;
import com.qdy.entity.CourseMembear;
import com.qdy.entity.user.User;
import com.qdy.repository.CourseMembearRepository;
import com.qdy.repository.VenueRepository;
import com.qdy.service.VenueServicer;
import com.qdy.util.HttpUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 场馆API接口
 * Created by 方礼爱 on 2017/3/25.
 */
@RequestMapping("/api/v1/venue")
@RestController
public class VenueAPIController {
    @Autowired
    private VenueRepository venueRepository;

    @Autowired
    private VenueServicer venueServicer;
    @Autowired
    private CourseMembearRepository courseMembearRepository;

    /**
     * 加载场馆信息
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value="/findVenue",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    public Object findVenue()throws ServiceException {
        try{
            return RestResultGenerator.genSuccessResult( venueRepository.findAll());
        }catch (Exception e){
            throw  new ServiceException(e.getMessage());
        }

    }





    /**
     * 加载场馆祥情
     * @param venueId
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value="/getVenueInfo/{venueId}",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    public  Object findVenueCourse(@PathVariable("venueId") String venueId)throws ServiceException {
        try {
             return RestResultGenerator.genSuccessResult(venueServicer.getVenueInfo(Long.valueOf(venueId)));
        }catch ( Exception e){
            throw new ServiceException("加载场馆课程失败",e.getMessage());
        }
    }




}
